package com.daocao.hua.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.daocao.hua.R;
import com.daocao.hua.adapter.base.ItemAdapter;
import com.daocao.hua.model.BonusModel;
import com.daocao.hua.util.DateTime;
import com.daocao.hua.util.ToastUtil;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/17 0017.
 */

public class YouhuiV2Adapter extends ItemAdapter<BonusModel.ListBean, YouhuiV2Adapter.YouhuiSelectViewHolder> {

    //    private Date nowDate;
    private float nowMoney;
    private Context context;
    private int use_status;

    public YouhuiV2Adapter(Context context, int type) {
        super(context);
//        nowDate = new Date();
        this.context = context;
        use_status = type;
    }


    private int selectPoi = 0;

    @Override
    public YouhuiSelectViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new YouhuiSelectViewHolder(inflate(R.layout.item_youhui_record, parent));
    }

    @Override
    public void onBindViewHolder(YouhuiSelectViewHolder holder, int position) {
        BonusModel.ListBean item = getItem(position);

        holder.txtType.setText(item.bonus_type_name + "\n借" + item.limit_amount + "元及以上金额可使用");
        holder.txtMoney.setText(item.money);

        if (item.isCheck) {
            holder.cbCheck.setImageResource(R.mipmap.img_pay_cb_open);
        } else {
            holder.cbCheck.setImageResource(0);
        }

        if (use_status == 1) {
            holder.imgStatus.setImageResource(R.mipmap.img_youhui_keyong);
        } else if (use_status == 2) {
            holder.imgStatus.setImageResource(R.mipmap.img_youhui_yiyong);
        } else if (use_status == 3) {
            holder.imgStatus.setImageResource(R.mipmap.img_youhui_guoqi);
        }
//        if (nowDate.before(new Date(item.use_end_time_format))) {
//            holder.imgStatus.setImageResource(R.mipmap.img_youhui_guoqi);
//        } else {
//            holder.imgStatus.setImageResource(R.mipmap.img_youhui_keyong);
//        }

        holder.txtDate.setText("有效期至" + DateTime.toDayUTF8Time(item.use_end_time_format * 1000));
//        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
////                if (nowDate.before(new Date(item.use_end_time_format))) {
////                    return;
////                }
//                if (item.limit_amount > nowMoney) {
//                    ToastUtil.makeText(context, "借" + item.limit_amount + "元及以上金额可使用").show();
//                    return;
//                }
//                getItem(selectPoi).isCheck = false;
//                selectPoi = position;
//                getItem(selectPoi).isCheck = true;
//                if (shareClickListener != null) {
//                    shareClickListener.onClick(item.id, item.bonus_type_name + "(" + item.money + "元)", item.money);
//                }
//                notifyDataSetChanged();
//            }
//        });
    }

    public void add(List<BonusModel.ListBean> listBeen, boolean init, float nowMoney) {
        this.nowMoney = nowMoney;
        super.add(listBeen, init);
    }

    public interface OnShareClickListener {
        void onClick(String bonus_id, String name, String money);
    }

    private OnShareClickListener shareClickListener;

    public void setShareClickListener(OnShareClickListener shareClickListener) {
        this.shareClickListener = shareClickListener;
    }

    class YouhuiSelectViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        @BindView(R.id.txt_money)
        TextView txtMoney;
        @BindView(R.id.txt_type)
        TextView txtType;
        @BindView(R.id.txt_date)
        TextView txtDate;
        @BindView(R.id.cb_check)
        ImageView cbCheck;
        @BindView(R.id.img_status)
        ImageView imgStatus;
        @BindView(R.id.layout_total)
        RelativeLayout layoutTotal;

        public void bindData() {

        }

        private YouhuiSelectViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void onClick(View v) {
        }
    }
}
